package com.awspaas.user.apps.shhtaerospaceindustrial.healthmeaasge;

import java.util.List;
import java.util.Map;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.bpmn.engine.core.delegate.ProcessExecutionContext;
import com.actionsoft.bpms.bpmn.engine.listener.ExecuteListener;
import com.actionsoft.bpms.bpmn.engine.model.run.delegate.ProcessInstance;
import com.actionsoft.bpms.commons.database.ColumnMapRowMapper;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.sdk.local.SDK;
import com.actionsoft.sdk.local.api.BOAPI;
import com.actionsoft.sdk.local.api.ProcessAPI;
import com.awspaas.user.apps.shhtaerospaceindustrial.util.CoreUtil;

public class CreateReportPrintApplyCard extends ExecuteListener{

	@Override
	public String getDescription() {
		return "节点审批结束，创建预约报告打印预订订单汇总卡片。";
	}
	
	@Override
	public void execute(ProcessExecutionContext param) throws Exception {
		String kp_prosid = "obj_4774573390a243aa893e28cb08a601f1";
		boolean flag_ok = SDK.getTaskAPI().isChoiceActionMenu(param.getTaskInstance(), "接单");
		//获取流程实例ID
		String processInstId = param.getProcessInstance().getId();
		if (flag_ok) {
			List<Map<String , Object>> headlist = DBSql.query("SELECT * FROM BO_EU_REPORTPRINT  WHERE BINDID = ? ", 
					new ColumnMapRowMapper(), new Object[] {processInstId});
			Map<String , Object>  datarecord = headlist.get(0);
				Object ID = datarecord.get("ID");// ID
				Object WORKERNAME = datarecord.get("WORKERNAME");// 职工姓名
				Object WORKERUNIT = datarecord.get("WORKERUNIT");// 职工单位
				Object PHONE = datarecord.get("PHONE");//联系电话
				Object WGDNAME = datarecord.get("WGDNAME");// 取报告地点
				Object REQUIRE = datarecord.get("REQUIRE");// 打印报告要求
				String FUJIAN = CoreUtil.objToStr(datarecord.get("FUJIAN"));// 人员明细
				Object WGDID = datarecord.get("WGDID");// 网格点ID
				Object WORKERID = datarecord.get("WORKERID");// 职工账号
				BO newcmsrecord = new BO();
				newcmsrecord.set("DDID",CoreUtil.objToStr(ID) );
				newcmsrecord.set("WORKERNAME",CoreUtil.objToStr(WORKERNAME));
				newcmsrecord.set("WORKERUNIT",CoreUtil.objToStr(WORKERUNIT));
				newcmsrecord.set("PHONE",CoreUtil.objToStr(PHONE));
				newcmsrecord.set("WGDNAME",CoreUtil.objToStr(WGDNAME));
				newcmsrecord.set("WGDNAME", CoreUtil.objToStr(WGDNAME));
				newcmsrecord.set("REQUIRE", CoreUtil.objToStr(REQUIRE));
				newcmsrecord.set("WGDID",CoreUtil.objToStr(WGDID));
				newcmsrecord.set("WORKERID",CoreUtil.objToStr(WORKERID));
				ProcessAPI proapi = SDK.getProcessAPI();
				// 创建一个仅存储的数据维护实例流程实例ID
				ProcessInstance processinstance = 
						proapi.createBOProcessInstance(kp_prosid, "admin", "预约报告打印订单汇总维护");
				BOAPI boapi = SDK.getBOAPI();
				int emrecordboId =boapi.create("BO_EU_YYBGDYDD_SUMMARY", newcmsrecord, 
						processinstance, null);	
				if(!"".equals(FUJIAN)) {
					String sql = "select id from BO_EU_YYBGDYDD_SUMMARY t where  t.DDID = '"
							+ CoreUtil.objToStr(ID) + "'";
					String sql1 = "select bindid from BO_EU_YYBGDYDD_SUMMARY t where  t.DDID = '"
							+ CoreUtil.objToStr(ID) + "'";
					String cardid = CoreUtil.objToStr(DBSql.getString(sql, "id"));// id
					String bindid = CoreUtil.objToStr(DBSql.getString(sql1, "bindid"));// bindid
					SDK.getBOAPI().copyFileTo(CoreUtil.objToStr(ID), "FUJIAN", cardid, "BO_EU_YYBGDYDD_SUMMARY",
							"FUJIAN", bindid, null);
					}
				}
	   }
	
	
}

